<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <f:metadata>
        <f:viewParam name="text" value="#{searchView.searchText}"> </f:viewParam>
        <f:viewParam name="page" value="#{searchView.backPage}"/>
        <f:viewAction action="#{searchView.init}"/>
    </f:metadata>

    <h:head>
        <title>search results</title>
        <style>@import url("../resources/css/homepageCSS1.css")</style>
    </h:head>

    <h:body>

        <p:layout fullPage="true">

            <p:layoutUnit styleClass="topLayout" position="north" size="100" resizable="true">
                <img id="titleImg" src="../resources/images/titolo90.png" alt="METEOCAL"/>
                <div id="userBlock">
                    <h:form>
                        <p:outputLabel>
                            #{userBean.name}&nbsp;&nbsp;&nbsp;<b>|</b>&nbsp;&nbsp;&nbsp;
                        </p:outputLabel>
                        <p:link style="color: blue;" value="Home" outcome="home?faces-redirect=true"/>
                        <p:outputLabel>
                            &nbsp;&nbsp;&nbsp;<b>|</b>&nbsp;&nbsp;&nbsp;
                        </p:outputLabel>
                        <p:commandLink style="color: blue;" action="#{loginBean.logout()}" value="Logout"/>
                    </h:form>
                </div>
                <div id="searchBar">
                    <h:form>
                        <p:inputText styleClass="inputTextStyleNoBorder" id="search" value="#{searchView.searchText}" required="true"/>
                        <p:commandButton value="" style="width: 32px; height: 32px; background: #000000 url(../resources/images/search_icon3.png) no-repeat top right" action="#{searchView.searchToInvite()}">
                        </p:commandButton>
                    </h:form>
                </div>
            </p:layoutUnit>
            <p:layoutUnit id="cent" position="center">

                <p:panel>
                    <h:form id="resultsForm">

                        <p:dataList emptyMessage="No results found." paginatorAlwaysVisible="false" paginatorPosition="bottom"  id="resList" var="user" value="#{searchView.results}" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                            <f:facet name="header">
                                Results for #{searchView.searchText}:
                            </f:facet>

                            <div padding="30px">
                                <p:commandLink update=":formmm:userDetail" oncomplete="PF('userDialog').show()" title="Invite this user" styleClass="ui-icon ui-icon-circle-plus" style="float:left;margin-right:50px">
                                    <f:setPropertyActionListener value = "#{user}" target="#{eventBean.selectedInvited}"/>
                                    <h:outputText value="#{user.firstName}, #{user.lastName}" />
                                </p:commandLink>
                                <h:outputText value="#{user.firstName} #{user.lastName} (#{user.email})" style="display:inline-block" />
                            </div>

                        </p:dataList>
                        <br/>
                        <p:dataList id="invitingList" emptyMessage="" paginatorAlwaysVisible="false" paginatorPosition="bottom" value="#{eventBean.invited}" var="user" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                            <f:facet name="header">
                                Invited
                            </f:facet>
                            <p:commandLink update="invitingList" title="Remove this user" styleClass="ui-icon ui-icon-circle-close" style="float:left;margin-right:50px">
                                <p:ajax update=":resultsForm:invitingList" listener="#{eventBean.remove(user)}" />
                            </p:commandLink>
                            <h:outputText value="#{user}" style="display:inline-block" />
                        </p:dataList>



                    </h:form>
                    <br/>
                    <h:form>
                        <p:commandButton id="back" value="Done" action="#{searchView.back()}"/>
                    </h:form>
                </p:panel>
                <br/>
            </p:layoutUnit>
        </p:layout>

        <h:form id="formmm">

            <p:dialog header="Confirm invitation" widgetVar="userDialog" modal="true" showEffect="blind" hideEffect="explode" resizable="false">
                <p:outputPanel id="userDetail" style="text-align:center;" >
                    <p:panelGrid columns="2" columnClasses="label,value">
                        <h:outputText value="First name:" />
                        <h:outputText value="#{eventBean.selectedInvited.firstName}" />

                        <h:outputText value="Last Name" />
                        <h:outputText value="#{eventBean.selectedInvited.lastName}" />

                        <p:commandButton title="Invite" value="Invite" oncomplete="PF('userDialog').hide()" 
                                         action="#{eventBean.invite()}" update=":resultsForm:invitingList,growl"/>
                        <p:growl id="growl" autoUpdate="true" globalOnly="true"/>
                    </p:panelGrid>
                </p:outputPanel>

            </p:dialog>
        </h:form>
    </h:body>
</html>